package com.sg.service.impl;
import com.github.pagehelper.PageHelper;
import com.sg.bean.Business;
import com.sg.dao.BusinessDao;
import com.sg.service.BusinessService;
import com.sg.util.MD5Util;
import com.sg.vo.BusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author zh
 * 商家业务逻辑访问实现类
 */
@Service
public class BusinessServiceImpl implements BusinessService {
    @Autowired
    BusinessDao businessDao;
    @Override
    public List<BusinessVO> findAll() {
        return businessDao.findAll();
    }

    @Override
    public List<BusinessVO> findAllPage(int pageNum,int pageSize) {
        //开启分页，pageNum页码pageSize
        PageHelper.startPage(pageNum,pageSize);
        return businessDao.findAll();
    }

    @Override
    public boolean findByTel(String businessTel) {
        return businessDao.findByTel(businessTel)!=null?true:false;
    }

    @Override
    public BusinessVO findByTelAadPass(Business business) {
        business.setBusinessPass(MD5Util.md5(business.getBusinessPass()));
        return businessDao.findByTelAadPass(business);
    }

    @Override
    public Business findById(int businessId) {
        return businessDao.findById(businessId);
    }

    @Override
    public List<Business> findByName(String businessName) {
        return businessDao.findByName(businessName);
    }

    @Override
    public boolean add(Business business) {
        business.setBusinessPass(MD5Util.md5(business.getBusinessPass()));
        return businessDao.add(business)>0?true:false;
    }

    @Override
    public boolean update(Business business) {
        return businessDao.update(business)>0?true:false;
    }

    @Override
    public boolean delete(int[] arrays) {
        return businessDao.delete(arrays)>0?true:false;
    }
}
